

import { registerClass } from "../../../cfw/tools/class_decorator";
import BaseAd from "../../core/base/BaseAd";
import { SDKLogicState, SDKState } from "../../SDKDefine";


@registerClass('GoogleBannerAd')
export default class GoogleBannerAd extends BaseAd {
    hide(): void {
        throw new Error("Method not implemented.");
    }
    load(): void {
        throw new Error("Method not implemented.");
    }
    show(): void {
        throw new Error("Method not implemented.");
    }


    create() {
        if (!this.ad) {
            this.ad = this.sdk.createBannerAd({
                adUnitId: this.adUnitID,
                layout: 1,
                width: 300,
                height: 100
            })
            this.ad.onLoad(this.onLoad.bind(this))
            this.ad.onError(this.onError.bind(this))
        }
        this.ad.load()
    }
    destroy(): void {
        console.log(' banner destroy', this.ad)
        if (this.ad) {
            this.ad.offLoad(this.getFunc(this.onLoad))
            this.ad.offError(this.getFunc(this.onError))
            this.ad.destroy();
            this.ad = null;
        }
    }

    onError(err: any) {
        this.setState(SDKState.loadFail)
    }

    onLoad() {
        this.setState(SDKState.loadSucess)
    }
}